const Condition = require('../models/Condition')

const addCondition = async (conditionObj) => {
  const res = await Condition.create({
    ...conditionObj
  })
  return res.toJSON() // 返回json格式的记录
}
const getCondition = async ()=>{
  const res = await Condition.findAll()
  return JSON.parse(JSON.stringify(res))
}
const deleteCondition = async (id)=>{
  const res = await Condition.destroy({
    where: {
      id,
    },
  });
  return res;
}
const updateCondition = async (id)=>{
  const result = await Condition.findByPk(id)
  if (result) {
    await result.update({ pass: true })
    return result.toJSON()
  } else {
    return false
  }
}

module.exports = {
  addCondition,
  getCondition,
  deleteCondition,
  updateCondition,
}
